package huoye.shops.base;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.Application;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.codeideology.android.AXIFragment;
import com.codeideology.android.http.okhttp.OkHttpUtils;
import com.codeideology.android.lang.entity.Pojo;
import com.codeideology.android.utils.ToastUtils;
import com.squareup.leakcanary.RefWatcher;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.Unbinder;


/**
 * Created by user on 2017/7/24.
 */

public abstract class BaseFragment extends AXIFragment {

    private static final String TAG = BaseFragment.class.getSimpleName();

    public static final String TYPE_START_MANAGE = "TYPE_START_MANAGE";

    public Bundle savedInstanceState;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = super.onCreateView(inflater, container, savedInstanceState);
        return view;
    }


    @Override
    public void onDestroy() {
        super.onDestroy();
        RefWatcher refWatcher = FSApplication.getRefWatcher(getActivity());
        if(refWatcher != null){
            refWatcher.watch(this);
        }
        OkHttpUtils.getInstance().cancelTag(this);
    }

    public void startActivity(Class<? extends Activity> aClass) {
        ((BaseActivity)getActivity()).startActivity(aClass);
    }

    public void startActivityFinish(Class<? extends Activity> aClass) {

    }

    public void startActivity(Class<? extends Activity> aClass, Bundle bundle) {

    }

    public void startActivity(Class<? extends Activity> aClass, Pojo pojo) {
        ((BaseActivity)getActivity()).startActivity(aClass, pojo);
    }


    /**
     * 通用界面跳转
     *
     * @param context
     * @param activty
     */
    public static void startActivityData(Context context, Class activty,boolean type) {
        Intent intentData = new Intent(context, activty);
        intentData.putExtra(TYPE_START_MANAGE,type);
        context.startActivity(intentData);
    }



    public void startActivityFinish(Class<? extends Activity> aClass, Bundle bundle) {

    }

    public void startActivityAndFinish(Class<? extends Activity> aClass, Bundle bundle, boolean b) {

    }

    public void finish() {

    }


    public void onNetworkFail() {
        this.makeToast("网络好像有点问题，请检查后重试");
    }

    public void makeToast(String text) {
        if(this.getActivity() != null && this.getActivity().getApplication() != null) {
            ToastUtils.makeToast(this.getActivity().getApplicationContext(), text);
        }
    }

    public void makeToast(int id) {
        if(this.getActivity() != null && this.getActivity().getApplication() != null) {
            ToastUtils.makeToast(this.getActivity().getApplicationContext(), id);
        }
    }





}

